

from ddt import ddt, unpack, data
from case_data.DailySignConfig import DailySignConfigData as config
from common import unittest


@ddt
class Daily_DailySignConfig(unittest.TestCase):

    @classmethod
    def setUpClass(cls):
        cls.png_list = [x.split("/")[-1] for x in cls.png]

    @data(*config().case)
    def test_base(self, row):
        self._testMethodDoc = f"测试id == {row['id']} 基础配置检查"
        self.assertGreater(row["groupId"], 0, f"id:{row['id']} groupId:{row['groupId']} 应大于0")
        self.assertIn(row["needCumulative"], [0, 1], f"id:{row['id']} needCumulative:{row['needCumulative']} 应配置为0或1")
        if row.get("dayNums"):
            self.assertGreater(row["dayNums"], 0, f"id:{row['id']} dayNums:{row['dayNums']} 应大于0")
            self.assertLess(row["dayNums"], 28, f"id:{row['id']} dayNums:{row['dayNums']} 为自然月时,该字段不用配置")
            self.assertEqual(row["dayNums"], len(row["reward"]), f"id:{row['id']} dayNums不为空时,应等于reward字段长度")
        else:
            self.assertEqual(len(row["reward"]), 31, f"id:{row['id']} dayNums配置为空时, reward字段长度应为31")
        self.assertIsNotNone(row.get("controllerName"), f"id:{row['id']} controllerName不能为空")
        self.assertIsNotNone(row.get("viewName"), f"id:{row['id']} viewName不能为空")
        self.assertEqual(len(row["btn"]), 2, f"id:{row['id']} btn:{row['btn']} 字段长度应为2")
        for png in row["btn"]:
            self.assertIn(png, self.png_list, f"id:{row['id']} btn:{png} 在图片路径中未找到")
            self.assertEqual(row["btn"].count(png), 1, f"id:{row['id']} btn:{png} 配置重复了")
        self.assertIn(row["bg"], self.png_list, f"id:{row['id']} bg:{row['bg']} 在图片路径中未找到")
        self.assertRegex(row["prefab"], ".+.prefab", f"id:{row['id']} prefab:{row['prefab']} 应以.prefab结尾")
        self.assertGreater(row["supactive"], 0, f"id:{row['id']} supactive:{row['supactive']} 应大于0")
        self.assertGreater(row["supcount"], 0, f"id:{row['id']} supcount:{row['supcount']} 应大于0")
        self.assertLess(row["supcount"], len(row["reward"]), f"id:{row['id']} supcount:{row['supcount']} 应小于reward字段长度")
        if row.get("effects"):
            self.assertRegex(row["effects"], "*.prefab", f"id:{row['id']} effects:{row['effects']} 应以.prefab结尾")

        self.assertLessEqual(len(row["effectadd"]), len(row["reward"]), f"id:{row['id']} effectadd字段长度应小于等于reward的字段长度")
        for effect in row["effectadd"]:
            self.assertGreater(effect, 0, f"id:{row['id']} effectadd:{effect} 应大于0")
            self.assertLessEqual(effect, len(row["reward"]), f"id:{row['id']} effectadd:{effect} 字段中的数应小于等于reward字段长度")
            self.assertEqual(row["effectadd"].count(effect), 1, f"id:{row['id']} effectadd:{effect} 配置重复了")

    @data(*config().in_lang("us"))
    @unpack
    def test_in_lang(self, row, lang):
        self._testMethodDoc = f"测试ID == {row['id']} name在语言表中查找"
        if row.get("name"):
            self.assertIn(str(row["name"]), lang, f"id:{row['id']} name:{row['name']} 在语言表中未找到")

    @data(*config().in_other("ObjList"))
    @unpack
    def test_in_other(self, row, ObjList):
        self._testMethodDoc = f"测试ID == {row['id']} reward关联到其他表测试"
        for drop_id in row["reward"]:
            self.assertIn(str(drop_id), ObjList, f"id:{row['id']} reward:{drop_id} 在ObjList表中未找到")
            self.assertEqual(row["reward"].count(drop_id), 1, f"id:{row['id']} reward:{drop_id} 配置重复了")
